package com.example.personalcenter;

import android.content.Intent;
import android.os.Bundle;
import android.widget.*;

import androidx.appcompat.app.AppCompatActivity;

public class ProfileEditActivity extends AppCompatActivity {

    private static final int REQ_INTEREST = 100;
    private String userName;
    private TextView tvInterest;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_profile_edit);

        userName = getIntent().getStringExtra("USER_NAME");

        Button btnBack = findViewById(R.id.btn_back);
        tvInterest = findViewById(R.id.tv_interest);

        btnBack.setOnClickListener(v -> finish());

        tvInterest.setText("兴趣未选择");
        tvInterest.setOnClickListener(v -> {
            Intent intent = new Intent(this, InterestActivity.class);
            startActivityForResult(intent, REQ_INTEREST);
        });

        ((TextView) findViewById(R.id.tv_user)).setText("用户名" + userName);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQ_INTEREST && resultCode == RESULT_OK && data != null) {
            String chosen = data.getStringExtra("INTEREST");
            tvInterest.setText("兴趣" + chosen);
        }
    }
}